<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
            <form id="editUserPwdForm" method="post">
                <table class="grid">
                    <tr>
                        <th>登录名：</th>
                        <td><span id="loginName"><shiro:principal></shiro:principal></span></td>
                    </tr>
                    <tr>
                        <th>原密码：</th>
                        <td><input name="oldPwd"  type="password" placeholder="请输入原密码" class="easyui-validatebox" data-options="required:true"></td>
                    </tr>
                    <tr>
                        <th>新密码：</th>
                        <td><input name="pwd" id="pwd" type="password"  placeholder="请输入新密码" class="easyui-validatebox" data-options="required:true,validType:['pwdComplex','canContainLoginName[\'#loginName\']']" ></td>
                    </tr>
                    <tr>
                        <th>重复密码：</th>
                        <td><input name="rePwd" type="password"  placeholder="请再次输入新密码" class="easyui-validatebox" data-options="required:true,validType:['pwdComplex','canContainLoginName[\'#loginName\']','eqPassword[\'#pwd\']']"></td>
                    </tr>
                </table>
            </form>
    </div>
</div>
<script type="text/javascript">
    $(function() {
    	$.extend($.fn.validatebox.defaults.rules, {
    	    pwdComplex:{
    	        validator:function(value,param){
    	            var reg = /^[\w]{8,20}$/;
    	            return reg.test(value);
    	        },
    	        message:  '至少字母、数字、_中的三种组合，长度至少8-20位复杂度'
    	    },
    	    eqPassword : { 
    	    	validator : function(value, param) {
    	    		return value == $(param[0]).val(); 
    	    	}, 
    	    	message : '两次输入密码不一致！' 
    	    },
    	    canContainLoginName:{
    	    	validator : function(value, param) {
    	    		
    	    		return -1 == value.search($(param[0]).text()); 
    	    	}, 
    	    	message : '密码中不能包含登录名' 
    	    }
    	});
    	
    	
        $('#editUserPwdForm').form({
            url : '${path }/user/editUserPwd',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    parent.$.messager.alert('提示', result.msg, 'info');
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    parent.$.messager.alert('错误', result.msg, 'error');
                }
            }
        });
    });
</script>s